home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
text
/
misc
/
EIQuotesV2.lha
/
quotes
/
Quotes.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-02
|
5KB
|
131 lines
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* OOOOOOO (tm) */
/* OOOOOOOOOOO Copyright © 1993 Engineering Ideas. */
/* OOOOOOOOOOOOO All Rights Reserved. */
/* OOOOOOOOOOOOO */
/* OOOOOOOOOOO OOO This program may not be distributed without */
/* OOOOOOO OOOOOOO prior permission from the author(s): */
/* OOOOOOOOO Richard Bemrose */
/* OOOOOOO */
/* OO OOO Engineering Ideas */
/* OOOOOO 22 Keppel View Road, Kimberworth, */
/* OO Rotherham, S. Yorks., S61 2AS, */
/* ENGLAND */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <libraries/dos.h>
#include <libraries/ppbase.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef LATTICE
#include <proto/all.h>
int CXBRK(void) {return(0);}
#endif
#include <proto/powerpacker.h>
#define ERR_INTUITION 1
#define ERR_NOPPLIB 2
#define ERR_NOARGS 3
#define ERR_PPMSG 4
#define ERR_FILE 5
struct PPBase *PPBase = NULL;
struct IntuitionBase *IntuitionBase = NULL;
void clean_up(UBYTE );
UBYTE *file = NULL; /* quotes file storage */
ULONG filelen; /* length of file */
UBYTE pperror; /* powerpacker error no. */
void main(int argc, char *argv[])
{
UBYTE *ptr;
UWORD rand_num, num_quotes=0;
ULONG seconds, micros;
if ( !(IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 0 )) )
clean_up(ERR_INTUITION);
if ( !(PPBase = (struct PPBase *) OpenLibrary ("powerpacker.library", 0L)) )
clean_up(ERR_NOPPLIB);
if (argc!=2)
clean_up(ERR_NOARGS);
/* Powerpackers clever stuff! Loads packed file then decruches it automatically */
pperror = ppLoadData (argv[1], DECR_NONE, MEMF_PUBLIC, &file, &filelen, NULL);
if (pperror)
clean_up(ERR_PPMSG);
/* Collects a random seed number from micro seconds */
CurrentTime( &seconds, µs );
srand(micros);
ptr=file;
while ( (*ptr++)!='\0' ) /* Counts no. of quotes */
if ( *ptr=='#' )
num_quotes++;
if ( num_quotes ) /* Any quotes in file */
{
rand_num=rand()%num_quotes; /* Picks random quote */
ptr=file;
while ( rand_num>0 ) /* Jumps to quote */
if ( (*ptr++)=='#' )
rand_num--;
while ( *ptr!='#' ) /* Prints quote */
putchar(*ptr++);
}
else
clean_up(ERR_FILE);
puts(NULL);
clean_up(0); /* Close everything */
}
void clean_up(UBYTE err)
{
if ( err )
puts ("Quotes V2 (c) 1993 Engineering Ideas.");
switch ( err ) /* Error messages */
{
case ERR_INTUITION:
puts ("Can not open Intuition Library.");
break;
case ERR_NOPPLIB:
puts ("You need powerpacker.library V33+ !");
break;
case ERR_NOARGS:
puts ("USAGE: Quotes <path/file>\n");
break;
case ERR_PPMSG:
printf ("Error: %s\n", ppErrorMessage (pperror));
break;
case ERR_FILE:
puts ("No quotes found in file. Insert # after each quote.");
default:
break;
}
if ( file ) /* A *must* for powerpacker */
FreeMem (file, filelen);
if ( PPBase )
CloseLibrary ((struct Library *)PPBase);
if ( IntuitionBase )
CloseLibrary( (struct Library *)IntuitionBase );
exit(0);
}